package com.skirmisher.video.aliVideo.stream;

import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vs.model.v20181212.*;
import com.skirmisher.video.aliVideo.BaseAliVideo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName AliStream
 * @Description TODO 阿里视频监控流处理
 * @Author hanwangxin
 * @Date 2020/11/7 6:12 下午
 * @Version 1.0
 */
@Service
public class AliStream extends BaseAliVideo {

    /**
     * @Author hanwangxin
     * @Description //TODO 获取流详情 * @Date 1:29 下午 2020/11/8
     * @Param [streamId]
     * @return com.aliyuncs.vs.model.v20181212.DescribeStreamResponse
     **/
    public DescribeStreamResponse describeStream(String streamId) throws ClientException {
        IAcsClient client = getClient();

        DescribeStreamRequest request = new DescribeStreamRequest();
        request.setId(streamId);

        DescribeStreamResponse acsResponse = client.getAcsResponse(request);
        return acsResponse;
    }

    /**
     * @Author hanwangxin
     * @Description //TODO 获取流列表 * @Date 1:31 下午 2020/11/8
     * @Param []
     * @return java.util.List<com.aliyuncs.vs.model.v20181212.DescribeStreamsResponse.Stream>
     **/
    public List<DescribeStreamsResponse.Stream> describeStreams(String deviceId) throws ClientException {
        IAcsClient client = getClient();

        DescribeStreamsRequest request = new DescribeStreamsRequest();
        request.setDeviceId(deviceId);

        DescribeStreamsResponse acsResponse = client.getAcsResponse(request);

        return acsResponse.getStreams();
    }

    /**
     * @Author hanwangxin
     * @Description //TODO 获取流的播放url * @Date 1:35 下午 2020/11/8
     * @Param [streamId, OutProtocol, AuthKey]
     * @return com.aliyuncs.vs.model.v20181212.DescribeStreamURLResponse
     **/
    public DescribeStreamURLResponse describeStreamURL(String streamId, String OutProtocol, String AuthKey) throws ClientException {

        IAcsClient client = getClient();

        DescribeStreamURLRequest request = new DescribeStreamURLRequest();

        request.setId(streamId);
        request.setOutProtocol(OutProtocol);
        request.setAuthKey(AuthKey);

        DescribeStreamURLResponse acsResponse = client.getAcsResponse(request);

        return acsResponse;

    }

    /**
     * @Author hanwangxin
     * @Description //TODO 播放流 * @Date 1:36 下午 2020/11/8
     * @Param [streamId]
     * @return void
     **/
    public void startStream(String streamId) throws ClientException {
        IAcsClient client = getClient();

        StartStreamRequest request = new StartStreamRequest();
        request.setId(streamId);

        client.getAcsResponse(request);
    }

    /**
     * @Author hanwangxin
     * @Description //TODO 关闭流 * @Date 1:37 下午 2020/11/8
     * @Param []
     * @return void
     **/
    public void stopStream(String streamId) throws ClientException {
        IAcsClient client = getClient();

        StopStreamRequest request = new StopStreamRequest();

        request.setId(streamId);

        client.getAcsResponse(request);


    }
}
